//
//  DeckLeftRecommendViewController.m
//  Car
//
//  Created by apple on 15/9/17.
//  Copyright (c) 2015年 朱鸿儒. All rights reserved.
//

#import "DeckLeftRecommendViewController.h"
#import "DeckCollectionViewCell.h"
#import "RecemmendTableViewController.h"


@interface DeckLeftRecommendViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) CALayer *layer;


//  item上的title
@property (nonatomic, strong) NSArray *fakeDataOnItemArray;


@end

@implementation DeckLeftRecommendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
 

    //  布局对象
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(60, 30);
    
    //  距 上 左 下 右
    layout.sectionInset = UIEdgeInsetsMake(50, 0, 0, 230);
    //  行距
    layout.minimumLineSpacing = 20;


    //  集合视图
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 300, kHeight)collectionViewLayout:layout];

    collectionView.delegate = self;
    collectionView.dataSource = self;

    UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
    view.image = [UIImage imageNamed:@"deck2.0.jpg"];
    
    collectionView.backgroundView = view;
    

    self.fakeDataOnItemArray = @[@"新闻", @"评测", @"导购", @"用车", @"技术", @"文化", @"游记", @"说客", @"改装"];
    
    
    
    //  注册
    [collectionView registerClass:[DeckCollectionViewCell class] forCellWithReuseIdentifier:@"tm"];


    [self.view addSubview:collectionView];
    
    self.layer = [[CALayer alloc] init];
    self.layer.position = CGPointMake(30, 65);
    self.layer.bounds = CGRectMake(0, 0, 50, 30);
    self.layer.cornerRadius = 10;
    self.layer.borderWidth = 3;
    self.layer.borderColor = [[UIColor colorWithRed:arc4random() % 256/255.0 green:arc4random() % 256/255.0 blue:arc4random() % 256/255.0 alpha:1.0] CGColor];
    
    [self.view.layer addSublayer:self.layer];
}


#pragma mark ---  添加背景图片



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}



//  tiem 个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.fakeDataOnItemArray.count;
    
}

//  cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    DeckCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"tm" forIndexPath:indexPath];
    
    cell.label.text = self.fakeDataOnItemArray[indexPath.item];
    cell.label.font = [UIFont fontWithName:@"Georgia-Italic" size:17];
    
    return cell;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    NSLog(@"aaa");
    
    
    NSString *no_row = [NSString stringWithFormat:@"%ld", indexPath.row];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"tm" object:nil userInfo:[NSDictionary dictionaryWithObject:no_row forKey:@"key"]];
    
    NSLog(@"%ld", indexPath.item);
    
    self.layer.borderColor = [[UIColor colorWithRed:arc4random() % 256/255.0 green:arc4random() % 256/255.0 blue:arc4random() % 256/255.0 alpha:1.0] CGColor];
    self.layer.position = CGPointMake(30, 65 + 50 * indexPath.item);
}


























@end
